package com.jiantu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jiantu.common.PageBean;
import com.jiantu.domain.dto.PageDTO;
import com.jiantu.domain.dto.StudentDTO;
import com.jiantu.domain.pojo.Students;
import com.jiantu.domain.vo.StudentVO;
import com.jiantu.mapper.StudentsMapper;
import com.jiantu.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentsServiceImpl implements StudentsService {

    @Autowired
    private StudentsMapper studentsMapper;

    @Override
    public Students findById(Integer id){
        return studentsMapper.findById(id);
    }

    @Override
    public PageBean findByPage(PageDTO pageDTO) {
        PageHelper.startPage(pageDTO.getPageNum(), pageDTO.getPageSize());
        List<StudentVO> studentList = studentsMapper.findByPage();
        Page p = (Page) studentList;
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public int insert(Students students){

        return studentsMapper.insert(students);
    }

    @Override
    public int update(StudentDTO studentDTO){

        return studentsMapper.update(studentDTO);
    }

    @Override
    public int deleteById(Integer id){

        return studentsMapper.deleteById(id);
    }

}
